package com.common.www.repository.tabulation;

import org.springframework.boot.base.jpa.repository.support.ExtendedRepository;
import com.common.www.bean.entity.tabulation.InnerTabulation;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface InnerTabulationRepository extends ExtendedRepository<InnerTabulation, Long> {

    /**
     *  按供应商查询
     * @param flag
     * @param biddingCompanyId
     * @return
     */
    List<InnerTabulation> findByFlagAndBiddingCompanyId(Integer flag, Long biddingCompanyId);

    /**
     * 按供应商和阶段查询
     * @param flag
     * @param biddingCompanyId
     * @param jieDuan
     * @return
     */
    List<InnerTabulation> findByFlagAndBiddingCompanyIdAndJieDuan(Integer flag,Long biddingCompanyId,Integer jieDuan);

    /**
     * 多供应商查询
     * @param biddingCompanyIds
     * @param jieDuan
     * @return
     */
    @Query(value = "SELECT * FROM inner_tabulation WHERE flag = 1 AND bidding_company_id IN (:biddingCompanyIds) AND jie_duan = :jieDuan", nativeQuery = true)
    List<InnerTabulation> getBiddingCompanyIdAndJieDuan(@Param("biddingCompanyIds") List<Long> biddingCompanyIds, @Param("jieDuan") Integer jieDuan);
    /**
     * 按供应商、阶段、分类查询
     * @param flag
     * @param biddingCompanyId
     * @param jieDuan
     * @param fenLei
     * @return
     */
    List<InnerTabulation> findByFlagAndBiddingCompanyIdAndJieDuanAndFenLei(Integer flag,Long biddingCompanyId,Integer jieDuan,Integer fenLei);

    /**
     * 按项目删除
     * @param biddingCompanyId
     * @param jieDuan
     * @return
     */
    @Modifying
    @Transactional
    int deleteByBiddingCompanyIdAndJieDuan(Long biddingCompanyId,Integer jieDuan);



}
